<?php

if(!$_SESSION) session_start();

if(!isset($_SESSION['UserID']) || $_SESSION['UserID'] == "") header("Location:index.php");
// Connect to the database
////////////////////////////////////////////////////////

require_once("scripts/config.php");

// Load Functions
////////////////////////////////////////////////////////

require_once("scripts/functions.php");

// Load Projects
////////////////////////////////////////////////////////

$sql = "SELECT * FROM tblprojects";

$projects = sqlLoad($sql, $db);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Project List - SynergyBugs | SynergyMX.com</title>
<style type="text/css">

.tnfck { color: #FFF; }
.hilight {background-color:#FFFFCC; ft-weight:700; cursor:pointer}

</style>
<script src="https://www.google.com/jsapi?key=<?php echo $api_key;?>" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

    google.load("jquery", "1.4.4");
    google.load("jqueryui", "1.8.6");

</script>
<script language="javascript" type="text/javascript" src="scripts/jquery-forms.js"></script>
<script language="javascript" type="text/javascript">

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function newProj(){

		$('#dia_addproj_detail').load('forms/project_new.php');

		$("#dia_addproj").dialog({
			bgiframe: true,
			width: 550,
			modal: true,
			position: 'top',
			beforeclose: function() {$(this).dialog('destroy');},
			buttons: {
				'Save and Add Project': function() {

					$('#formNP').ajaxSubmit({target:'#dia_addproj_detail'});

					location.reload();

					return false;


				},
				Cancel: function() {
					$(this).dialog('destroy');
				}
			}
		});

	};

function editProj($id){

		$('#dia_editproj_detail').load('forms/project_edit.php?ID='+$id);

		$("#dia_editproj").dialog({
			bgiframe: true,
			width: 550,
			modal: true,
			position: 'top',
			beforeclose: function() {$(this).dialog('destroy');},
			buttons: {
				'Save and Update Project': function() {

					$('#formUP').ajaxSubmit({target:'#dia_editproj_detail'});

					location.reload();

					return false;


				},
				Cancel: function() {
					$(this).dialog('destroy');
				}
			}
		});

	};


</script>
<link href="scripts/style.css" rel="stylesheet" type="text/css" />
<link href="scripts/jquery-ui-1.7.2.custom.css" rel="stylesheet" type="text/css" />

</head>
<body>
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td class="tnbg"><table align="center" width="780" border="0" cellspacing="0" cellpadding="0">
                  <tr><td width="195"><a href="home.php"><img src="/images/logo.png" width="195" height="56" border="0"></a></td><td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td class="tnfck ft8b" height="16" align="right">Welcome Back, <?php echo $_SESSION['name_display'];?>&nbsp;&nbsp;::&nbsp;&nbsp;Sign Out</td>
                    </tr>
                    <tr>
                      <td height="40" align="right"><form id="form1" name="form1" method="post" action="">
                      <a href="home.php"> Task List</a>&nbsp;|&nbsp;
                        <a href="javascript:;" onclick="newProj();">add projects</a>&nbsp;|&nbsp;
                          <input name="Search" type="text" id="Search" value="Search" />

                          <select name="fbs" id="fbs">
                            <option value="all">All Status</option>
                          </select>

<input name="Refresh" type="submit" id="Refresh" value="Refresh" />

                      </form></td>
                    </tr>
                </table></td></tr></table></td>
              </tr>
              <tr>
                <td>
<table width="780" border="0" cellspacing="0" cellpadding="0" align="center">
<tr>
<td>
Current Project List
<?php if(sizeof($projects) == 0){

	echo "No projects found...";

}

foreach ($projects as $project){ ?>
<div><img src="images/active<?php echo $project['set_active'];?>.gif" align="absbottom" /> <?php echo $project['project_label'];?> <a href="javascript:;" onclick="editProj(<?php echo $project['ProjectID'];?>);"><img src="images/cog.gif" align="absbottom" border="0" /></a></div>
<?php } ?>
<div id="dia_addproj" name="dia_addproj" title="Add a Project">
    <div id="dia_addproj_detail" name="dia_addproj_detail"></div>
</div>
<div id="dia_editproj" name="dia_editproj" title="Update Project">
    <div id="dia_editproj_detail" name="dia_editproj_detail"></div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
